就是一个datagrid控件,显示出来的时候,我想要每条记录前都有一个单选控件,点击哪一个就相当于选中那条记录,单选控件,最好是动态生成,因为我不知道有多少条记录,---给datagrid加一个模板列,给一个html的radiobutton另外还有一个问题,Datagrid里有一个列我想把它改为可修改,我想点下那个某一行记录的那个列后,就变为可改写状态,然后关键的是在那个列里写了数据后,这时没有写入到数据库,等我按下确定后才写入数据库(因为我有可能想修改多条记录的在Datagrid上) ----编辑datagrid的edit列

解决方案 »

  1.   

    很多方法, 用模块列放radiobox. 继续DataGridColumn, 自己写一个radiobox的列, 然后绑定.请看:
    http://www.microsoft.com/china/msdn/archives/library/dnaspp/html/creatingcustomcolumns.asp
      

  2.   

    hello!
    I think you can create a template column in the datagrid and place the asp:RadioButton inside.I can give your a example for the session:step 1,You must create a DataGrid for your application,it look like this:
    <asp:DataGrid id="DataGrid1" style="Z-INDEX: 105; LEFT: 176px; POSITION: absolute; TOP: 72px"
    runat="server" AutoGenerateColumns="False">
    <Columns>
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:RadioButton id="RadioButton1" runat="server"></asp:RadioButton>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:BoundColumn HeaderText="Other Fields"></asp:BoundColumn>
    </Columns>
    </asp:DataGrid>
    step 2,during the page load attach the onclick event with the javascript function.It look like this:
    foreach(DataGridItem item in this.DataGrid1.Items) { 
       RadioButton rd = (RadioButton)item.FindControl("RadioButton1");
       rd.Attributes.Add("onclick", "javascript:SelectChange(" + rd.UniqueID.Replace(":","_")  + ");");   
    }last, you can check radiobutton of DataGrid one by one .and get its state!good luck!
      

  3.   

    SelectChange is a javascript function,You must implement it!
      

  4.   

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchTopQuestionsAboutASPNETDataGridServerControl.asp
      

  5.   

    Adding radio buttons to the datagridhttp://www.mike-levin.com/highlight/adding-radio-buttons-to-the-datagrid.html
      

  6.   

    public void SetFalse(object sender, System.EventArgs e)
    {
    RadioButton rdo = (RadioButton)sender;
    TableCell cell = (TableCell)rdo.Parent;
    DataGridItem item = (DataGridItem)cell.Parent;
    for(int i = 0; i < this.dtgtruck.Items.Count; i++)
    {
    if(i != item.ItemIndex)
    {
    RadioButton rbt = (RadioButton)this.dtgtruck.Items[i].FindControl("rbttruck");
    rbt.Checked = false;
    }
    else
    {
    if(this.dtgtruck.Items[i].Cells[6].Text=="1")
    {
    this.dtgdriver.Visible=false;
    this.ddlend.Visible=false;
    this.lblwhy.Visible=true;
    this.Label3.Visible=false;
    this.ddlselect.Visible=false;
    this.lblone.Visible=false;
    this.lbltwo.Visible=false;
    string strUT;
    strUT=" SELECT * FROM GOODS_CAR WHERE GC_TRUCK_CODE='"+this.dtgtruck.Items[i].Cells[2].Text.ToString() +"'";
    DataSet dsUT=new DataSet();
    dsUT=Info.Select(strUT,"GOODS_CAR");
    this.lblwhy.Text=dsUT.Tables["GOODS_CAR"].Rows[0]["GC_END"].ToString();
    }
    else
    {
    this.dtgdriver.Visible=true;
    this.ddlend.Visible=true;
    this.lblwhy.Visible=false;
    this.Label3.Visible=true;
    this.ddlselect.Visible=true;
    this.lblone.Visible=true;
    this.lbltwo.Visible=true;
    }
    // else
    // {
    // string strDrive;
    // strDrive="SELECT * FROM USER_DRIVE WHERE UD_USER="+Session["USER_ID"]+" AND UD_STATUS="+0+"";
    // DataSet dsDrive=new DataSet();
    // dsDrive=Info.Select(strDrive,"USER_DRIVE");
    // this.dtgdriver.DataSource=dsDrive;
    // this.dtgdriver.DataBind();
    // if(dsDrive.Tables["USER_DRIVE"].Rows.Count>0)
    // {
    // this.lbltwo.Visible=false;
    // }
    // else
    // {
    // this.lblone.Visible=false;
    //
    // }
    // }
    }
    }
    }
    public void SetFalseone(object sender, System.EventArgs e)
    {
    RadioButton rdo = (RadioButton)sender;
    TableCell cell = (TableCell)rdo.Parent;
    DataGridItem item = (DataGridItem)cell.Parent;
    for(int j = 0; j< this.dtgdriver.Items.Count; j++)
    {
    if(j != item.ItemIndex)
    {
    RadioButton chk = (RadioButton)this.dtgdriver.Items[j].FindControl("rbtdrive");
    chk.Checked = false;
    }
    }
    }
    private void btnsubmit_Click(object sender, System.EventArgs e)
    {
    string[,] str = new string[100,2];
    str = (string[,])Session["STR"];
       int g=0;
    int k=0;
    int h=0;
    string a="",b="";
    int utweight=0;
    string strTruck;
    strTruck=" SELECT * FROM USER_TRUCK WHERE UT_USER="+Session["USER_ID"]+" AND UT_STATUS="+0+" OR UT_USER="+Session["USER_ID"]+" AND UT_STATUS="+1+"";
    DataSet dsTruck=new DataSet();
    dsTruck=Info.Select(strTruck,"USER_TRUCK");
    for(int i=0;i<dsTruck.Tables["USER_TRUCK"].Rows.Count;i++)
    {
    RadioButton rbt =new RadioButton();
    rbt=(RadioButton)this.dtgtruck.Items[i].FindControl("rbttruck");
    if(rbt.Checked==true)
    {
    k=1;
    utweight=System.Convert.ToInt32(dsTruck.Tables["USER_TRUCK"].Rows[i]["UT_WEIGHT"].ToString());
    a=dsTruck.Tables["USER_TRUCK"].Rows[i]["UT_CODE"].ToString();
    g=System.Convert.ToInt32(dsTruck.Tables["USER_TRUCK"].Rows[i]["UT_STATUS"].ToString());

    }
    }
    if(g==0)
    {
    string strDrive;
    strDrive="SELECT * FROM USER_DRIVE WHERE UD_USER="+Session["USER_ID"]+" AND UD_STATUS="+0+"";
    DataSet dsDrive=new DataSet();
    dsDrive=Info.Select(strDrive,"USER_DRIVE"); 
    for(int j=0;j<dsDrive.Tables["USER_DRIVE"].Rows.Count;j++)
    {
    RadioButton chk =new RadioButton();
    chk=(RadioButton)this.dtgdriver.Items[j].FindControl("rbtdrive");
    if(chk.Checked==true)
    {
    h=1;
    b=dsDrive.Tables["USER_DRIVE"].Rows[j]["UD_NUMBER"].ToString();
    }
    }
    if(k==1&&h==1)
    {
    if (this.ddlend.SelectedItem.Text !="请选择:")
    {
    if (this.ddlselect.SelectedItem.Text !="请选择:")
    {
    GetPath(this.lblstart.Text.ToString(),0,this.lblstart.Text.ToString(),this.ddlend.SelectedItem.Text.ToString(),0);
    string[,] Path = new string[1000,3];
    Path = (string[,])Session["path"];
    double min=9999999999;
    string temp;
    int j=0;
    string Short="";
    if (this.ddlselect.SelectedItem.Value.ToString()=="1")
    {
    for(int i=0;i<Path.Length;i++)
    {
    if (Path[i+1,1]!=null)
    {
    if (Path[i+1,1].ToString()!="")
    {
    temp = Path[i+1,1];                
    if (System.Convert.ToDouble(temp)<min)
    {
    min = System.Convert.ToDouble(temp);
    j = i+1;
    }
    i =  i+1;
    }
    else
    {
    break;
    }
    }
    else
    {
    break;
    }
    }
    Short = Path[j,0];
    }
    else if(this.ddlselect.SelectedItem.Value.ToString()=="2")
    {
    for(int i=0;i<Path.Length;i++)
    {
    if (Path[i+1,2]!=null)
    {
    if (Path[i+1,2].ToString()!="")
    {
    temp = Path[i+1,2];                
    if (System.Convert.ToDouble(temp)<min)
    {
    min = System.Convert.ToDouble(temp);
    j = i+1;
    }
    i =  i+1;
    }
    else
    {
    break;
    }
    }
    else
    {
    break;
    }
    }
    Short = Path[j,0];
    }